package cn.fl.warrant.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import tc.esign.facade.esign.dto.FilSignDTO;
import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.system.service.ISysBkInfoApiService;
import cn.fl.warrant.service.IWarrantFileManageMService;
import cn.fl.warrant.transform.ArcMgrDetailVOTransform;
import cn.fl.warrant.transform.WarrantFileManageVOTransform;
import cn.fl.warrant.vo.ArcMgrDetailVO;
import cn.fl.warrant.vo.ArcMgrMainVO;
import cn.fl.warrant.vo.WarrantFileManageVO;
import fl.ass.facade.condition.AssDealCarQueryCondition;
import fl.ass.facade.condition.AssTrailCarDQueryCondition;
import fl.ass.facade.condition.AssTrailCarHvQueryCondition;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.warrant.facade.archive.api.IWarrantFileManageApiService;
import fl.warrant.facade.archive.condition.ArcBscInfoQueryCondition;
import fl.warrant.facade.archive.condition.ArcMgrDetailQC;
import fl.warrant.facade.archive.condition.ArcMgrMainQC;
import fl.warrant.facade.archive.condition.WarrantFileManageQueryCondition;
import fl.warrant.facade.archive.dto.ArcBscInfoDTO;
import fl.warrant.facade.archive.dto.ArcMgrDetailDTO;
import fl.warrant.facade.archive.dto.ArcMgrMainDTO;
import fl.warrant.facade.archive.dto.MessageDTO;
import tc.esign.facade.esign.dto.FilSignDTO;
/**
 * @Description: 档案管理 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class WarrantFileManageServiceImpl implements IWarrantFileManageMService {

	private static final Logger logger = LoggerFactory.getLogger(IWarrantFileManageMService.class);
	

	
	/**
	 * 数据字典 API 暴露服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApi;
	
	/**
	 * 查询流程API 暴露服务
	 */
	@Autowired
	private IFlowQueryApiService flowQueryApi;
	
	/**
	 * 查询银行API 暴露服务
	 */
	@Autowired
	private ISysBkInfoApiService sysBkInfoApi;

	/**
	 * 文档管理
	 */
	@Autowired
	private IWarrantFileManageApiService warrantFileManageApiService;
	
	


	@Override
	public Long addWarrantFileManage(WarrantFileManageVO entity) throws BaseException{
		MessageDTO<String> response = this.warrantFileManageApiService.addWarrantFileManage(WarrantFileManageVOTransform.toDTO(entity));
		return response.getId();
	}


	/**
     * 拖车模块-发起流程
     * @param qc
     * @return
     * @throws BaseException
     */
	@Override
    public DataResultVO startFlow(WarrantFileManageQueryCondition qc) throws BaseException {
		DataResultVO resultVO = null;
        //发起流程
//        DataResultDTO resultDTO = this.assTrailCarApi.addTrailCarApply(qc);
		DataResultDTO resultDTO = this.warrantFileManageApiService.startFlow(qc);
        if(resultDTO != null){
            resultVO = new DataResultVO(Integer.parseInt(resultDTO.getCode()),resultDTO.getInfo());
        }else{
            resultVO = new DataResultVO(BaseConstant.IS_YESNO_NO,"流程发起失败");
        }
        return resultVO;
    }
	
	/**
	 * 根据字段代码组获取代码值集合
	 * @param grpCd 代码组值
	 * @param sysCd 系统代码
	 * @param orgCd 组织结构代码
	 * @return 值
	 * @throws BaseException
	 */
	@Override
	public List<KeyValueVO> getKvList(String sysCd, String orgCd,String grpCd) throws BaseException {
		List<KeyValueVO>  keyValueList = null;
		List<SysDictionaryDTO>  dictionaryList = this.sysDictionaryApi.searchGroup(sysCd, orgCd, grpCd);
		if(CollectionUtils.isNotEmpty(dictionaryList)){
			keyValueList = new ArrayList<>();
			for (SysDictionaryDTO sysDictionaryDTO : dictionaryList) {
				KeyValueVO keyValue = new KeyValueVO();
				keyValue.setKey(sysDictionaryDTO.getCode());
				keyValue.setValue(sysDictionaryDTO.getCodeNm());
				keyValueList.add(keyValue);
			}
		}
		return keyValueList;
	}

	/**
	 * 档案资料下载列表
	 * zhangrongcong
	 */
	@Override
	public Pager selectListForDownListPage(Pager page) throws BaseException {
		if(null == page)page = new Pager();
		return this.warrantFileManageApiService.selectListForDownListPage(page,  CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		
	}

	/**
	 * 归档超期提醒
	 * zhangrongcong
	 */
	@Override
	public Pager selectListForListPage(Pager page) {
		if(null == page)page = new Pager();
		return this.warrantFileManageApiService.selectListForListPage(page,  CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		
	}

	/**
	 * 查看档案资料
	 * zhangrongcong
	 */
	@Override
	public List<ArcMgrDetailDTO> searchArchiveList(ArcMgrDetailQC condition) throws BaseException {
		return this.warrantFileManageApiService.searchArchiveList(condition);
	}

	/**
	 * 借阅超期提醒
	 * @param page
	 * @return
	 * @throws BaseException
	 */
	@Override
	public Pager selectBorrowOverdueListPage(Pager page) {
		if(null == page)page = new Pager();
		return this.warrantFileManageApiService.selectBorrowOverdueListPage(page,  CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		
	}

	/**
	 * 导出归档超期模块信息
	 */
	@Override
	public String exportPayInfo(ArcMgrMainQC condition,String eFlag)throws BaseException {
		return this.warrantFileManageApiService.exportPayInfo(condition,eFlag,CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
	}

	/**
	 * 导出借阅超期模块信息
	 */
	@Override
	public String exportBtnEvent(ArcMgrMainQC condition) {
		return this.warrantFileManageApiService.exportBtnEvent(condition,CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
	}

	@Override
	public List<ArcMgrMainDTO> selectListForListPageToexcle(ArcMgrMainQC qc) {
		return this.warrantFileManageApiService.selectListForListPageToexcle(qc,CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		
	}


	

	
}
